<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let obj = {
            name: 'twj',
            age: 600,
            data: {
                list: ['aaa', 'bbb', 'ccc']
            }
        }
        //对象解构不需要按照顺序来，是先按照属性名找有没有，找到再赋值给相应的变量
        let { age, name } = obj;
        console.log(name, age); // twj 600
        let { data: { list }, name: n, age: a, err = '没有错误' } = obj;
        console.log(list, n, a, err); // [aaa,bbb,ccc] twj 600 没有错误

        function getData() {
            let obj = {
                name: 'twj',
                age: 600,
                data: {
                    list: ['aaa', 'bbb', 'ccc']
                }
            }
            test(obj)
        }
        function test({ name, data: { list } }) {
            console.log(name, list); //twj [aaa,bbb,ccc]
        }
        getData();
    </script>
</body>

</html>